<?php

namespace App\Http\Controllers;

use App\Common\Helper\ApiReturnHelper;
use App\Models\User;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;

class AuthController extends Controller
{

    /**
     * 登录
     * @return void
     * @author 我只想看看蓝天 <1207032539@qq.com>
     */
    public function testLogin()
    {
        $res = [
            'token' => Auth::guard('api')->login(User::find(1)),
            'ttl' => config('jwt.ttl') * 60,
        ];
        return ApiReturnHelper::newInstance()->successResponse('获取成功', $res);
    }

    /**
     * 获取用户信息
     * @return \Illuminate\Http\JsonResponse|null
     * @author 我只想看看蓝天 <1207032539@qq.com>
     */
    public function me()
    {
        $res = Auth::user();
        return ApiReturnHelper::newInstance()->successResponse('获取成功', $res);
    }

    /**
     * 刷新令牌
     * @return \Illuminate\Http\JsonResponse|null
     * @author 我只想看看蓝天 <1207032539@qq.com>
     */
    public function refresh()
    {
        $res = [
            'token' => \auth('api')->refresh(),
            'ttl' => config('jwt.ttl') * 60,
        ];
        return ApiReturnHelper::newInstance()->successResponse('获取成功', $res);
    }
}
